﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ClientCommonClass
{
    /// <summary>
    /// 客户端 公共静态方法与常量
    /// </summary>
    public static class ClientUtilities
    {
        #region Win32API 方法包装

        [DllImport("user32.dll")]
        static extern void BlockInput(bool Block);

        [DllImport("user32.dll")]
        public static extern bool LockWorkStation(); // Win + L

        [DllImport("user32")]
        public static extern long ExitWindowsEx(long uFlags, long dwReserved);

        #endregion

        #region 方法

        /// <summary>
        /// 关闭计算机
        /// </summary>
        public static void ShutDownPC()
        {
            /* 针对本机有效，远程主机无效！
            Process process = new Process();
            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true; 
            process.Start();
            process.StandardInput.WriteLine("shutdown -s -t 0");*/

            WindowsExit.PowerOff(); // 关机
        }

        /// <summary>
        /// 锁屏
        /// </summary>
        public static void LockPC()
        {
            BlockInput(true); // 锁定鼠标及键盘
        }

        /// <summary>
        /// 解屏
        /// </summary>
        public static void UnlockPC()
        {
            BlockInput(false); // 解除鼠标及键盘的锁定
        }

        #endregion
    }
}
